package com.five.monkey.feign.provider.convert;

import com.five.monkey.feign.provider.dao.model.UserModel;
import com.five.monkey.util.TimeUtils;
import com.five.monkey.vo.UserVo;
import java.util.Objects;

/**
 * @author 狻猊
 * @date 2021/8/10 下午5:25
 */
public class UserConvert {

    private UserConvert() {}

    public static UserVo model2vo(UserModel user) {
        if (Objects.isNull(user)) {
            return null;
        }
        UserVo vo = new UserVo();
        vo.setId(user.getId()).setName(user.getName()).setPassword(user.getPassword()).setStatus(user.getStatus())
                .setCreateTime(TimeUtils.parseDate(user.getCreateTime()))
                .setUpdateTime(TimeUtils.parseDate(user.getUpdateTime()));
        return vo;
    }

    public static UserModel vo2model(UserVo vo) {
        if (Objects.isNull(vo)) {
            return null;
        }
        UserModel user = new UserModel();
        user.setId(vo.getId()).setName(vo.getName()).setPassword(vo.getPassword()).setStatus(vo.getStatus())
                .setCreateTime(TimeUtils.ofDate(vo.getCreateTime()))
                .setUpdateTime(TimeUtils.ofDate(vo.getUpdateTime()));
        return user;
    }
}
